'use strict';
const db = uniCloud.database()
//event为客户端上传的参数
exports.main = async (event, context) => {
	const {classify,page=1,pageSize=10} = event
	let matchObj = {}
	if(classify !=='全部') {
		matchObj = {classify}
	}
	//聚合，筛选
	const list = await db.collection('article').aggregate().
	match(matchObj).
	project({
		content:0
	}).skip((page-1)*pageSize) // 第一页数据从0开始
	.limit(pageSize) // 每页返回多少条数据
	.end()
	
	// 返回当前匹配的选项里的数据总数
	const amount = await db.collection('article').where(matchObj).count()
	
	//返回数据给客户端
	return {
		code: 200,
		data: {
			articleList:list.data,
			total: amount.total
		},
		msg: '数据获取成功'
	}
};
